package com.sky.service.impl;

import com.sky.mapper.OrderMapper;
import com.sky.service.ReportService;
import com.sky.vo.TurnoverReportVO;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public TurnoverReportVO getTurnoverReport(LocalDate begin, LocalDate end) {
        List<LocalDate> dateList = null;
        while(begin.plusDays(1)!=end){
            dateList.add(begin);
            begin=begin.plusDays(1);
        }
        String datelist=StringUtil.join(",", dateList);
        List<Double> turnoverList = null;
        for (LocalDate date : dateList) {
            LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
            LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);
            turnoverList.add(orderMapper.getTurnoverByDate(beginTime,endTime,5));
        }
        String turnoverlist=StringUtil.join(",", turnoverList);
        return TurnoverReportVO
                .builder()
                .dateList(datelist)
                .turnoverList(turnoverlist).build()
                ;
    }
}
